package com.lagou.test.com.lagou.dao;

import com.lagou.io.Resources;
import com.lagou.pojo.User;
import com.lagou.sqlSession.DefaultSqlSession;
import com.lagou.sqlSession.SqlSession;
import com.lagou.sqlSession.SqlSessionFactory;
import com.lagou.sqlSession.SqlSessionFactoryBuilder;
import org.dom4j.DocumentException;

import java.beans.PropertyVetoException;
import java.io.InputStream;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import java.util.List;

public class UserDao implements  IUserDao{
    @Override
    public List<User> findAll() throws PropertyVetoException, DocumentException {
        InputStream resourceAsSteam = Resources.getResourceAsSteam("sqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder().build(resourceAsSteam);
        SqlSession sqlSession = sqlSessionFactoryBuilder.openSession();

        //调用
        User user = new User();
        user.setId(1);
        user.setUsername("lucy");
        User user1 = sqlSession.selectOne("user.selectOne", user);
        System.out.println(user1.toString());

        List<User> users = sqlSession.selectList("user.selectList");
        return users;
    }

    @Override
    public User findByCondition(User user) throws PropertyVetoException, DocumentException {
        InputStream resourceAsSteam = Resources.getResourceAsSteam("sqlMapConfig.xml");
        SqlSessionFactory sqlSessionFactoryBuilder = new SqlSessionFactoryBuilder().build(resourceAsSteam);
        SqlSession sqlSession = sqlSessionFactoryBuilder.openSession();

        //调用
        user.setId(1);
        user.setUsername("lucy");
        user = sqlSession.selectOne("user.selectOne", user);
        return  user;
    }

    @Override
    public Boolean updateById(User user) throws PropertyVetoException, DocumentException {
        return null;
    }

    @Override
    public Boolean add(User user) throws PropertyVetoException, DocumentException {
        return null;
    }

    @Override
    public Boolean deleteById(User user) throws PropertyVetoException, DocumentException {
        return null;
    }


}
